package ink.yuanchu.picachoframework.message;

import com.alibaba.fastjson.JSONObject;
import ink.yuanchu.picachoframework.entity.Permissions;
import ink.yuanchu.picachoframework.entity.User;
import ink.yuanchu.picachoframework.util.JwtTokenUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 消息处理类
 * @author ziyuan
 */
public class Message {

    /**
     * 登录失败,用户名或密码错误
     */
    public static final String ERROR_USERNAME_OR_PASSWORD = "登录失败,用户名或密码错误";

    /**
     *获取路由失败
     */
    public static final String ERROR_GET_ROUTER = "获取路由失败";

    /**
     * 用户不存在
     */
    public static final String USER_DOES_NOT_EXIST = "用户不存在";

    /**
     * 未知异常
     */
    public static final String UNKNOWN_EXCEPTION = "未知异常";

    /**
     * 账号过期
     */
    public static final String ACCOUNT_EXPIRED = "账号过期";

    /**
     * 密码过期
     */
    public static final String PASSWORD_EXPIRED = "密码过期";

    /**
     * 账号不可用
     */
    public static final String ACCOUNT_NOT_AVAILABLE = "账号不可用";

    /**
     * 账号锁定
     */
    public static final String ACCOUNT_LOCKOUT = "账号锁定";

    /**
     * 密码错误
     */
    public static final String WRONG_PASSWORD = "密码错误";

    /**
     * 未登录，没有访问权限
     */
    public static final String NO_LOGIN_NO_ACCESS = "您未登录，没有访问权限";

    /**
     * 文件路径不存在
     */
    public static final String FILE_PATH_DOES_NOT_EXIST = "文件路径不存在";

    /**
     * 文件不存在
     */
    public static final String FILE_DOES_NOT_EXIST = "文件不存在";

    /**
     * 上传成功
     */
    public static final String UPLOAD_SUCCESS = "上传成功";

    /**
     * 上传失败
     */
    public static final String UPLOAD_ERROR = "上传失败";


    /**
     * 登录错误
     * @param httpStatus
     * @param errorMessage
     * @return
     */
    public static ResponseEntity<JSONObject> errorLogin(HttpStatus httpStatus,String errorMessage){
        return  new ResponseEntity<JSONObject>(errorMessage(httpStatus.value(), errorMessage), httpStatus);
    }

    /**
     * 登录错误消息封装成json
     * @param httpStatus
     * @param errorMessage
     * @return
     */
    public static JSONObject errorLoginToJson(HttpStatus httpStatus,String errorMessage){
        return  errorMessage(httpStatus.value(), errorMessage);
    }



    /**
     * 错误信息封装
     * @param httpStatus
     * @param message
     * @return
     */
    public static JSONObject errorMessage(int httpStatus, String message){
        JSONObject jsonObject=new JSONObject();
        Map result = new HashMap();
        result.put("isLogin",true);
        jsonObject.put("code",httpStatus);
        jsonObject.put("message",message);
        jsonObject.put("result",result);
        return jsonObject;
    }
}
